package com.tanhua.server.controller;

import com.tanhua.server.service.TodayBestService;
import com.tanhua.server.vo.SoundVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * @Author YuShiLong
 * @Date 2021/4/27 10:27
 * @Version 1.0
 */
@RestController
@RequestMapping("peachblossom")
public class SoundController {

    @Autowired
    private TodayBestService todayBestService;

    /**
     * 发送语音
     *
     * @param soundFile 语音文件
     * @return
     */
    @PostMapping
    public ResponseEntity<String> sendVoice(@RequestParam(value = "soundFile", required = false) MultipartFile soundFile) {

        try {
            //调用service层的发送语音的方法,发送语音,并判断是否发送成功
            Boolean bool = todayBestService.sendVoice(soundFile);
            if (bool) {
                return ResponseEntity.ok(null);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
    }

    /**
     * 接收语音
     *
     * @return
     */
    @GetMapping
    public ResponseEntity<SoundVo> querySound() {
        try {
            SoundVo soundVo = todayBestService.querySound();
            if (null != soundVo) {
                return ResponseEntity.ok(soundVo);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
    }
}
